{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "relevant-mercury",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/random-pick-index\n",
    "\n",
    "\n",
    "Runtime: 160 ms, faster than 35.07% of C++ online submissions for Random Pick Index.\n",
    "Memory Usage: 53.7 MB, less than 11.58% of C++ online submissions for Random Pick Index.\n",
    "\n",
    "\n",
    "```cpp\n",
    "#include <vector>\n",
    "#include <algorithm>\n",
    "#include <string>\n",
    "#include <map>\n",
    "#include <vector>\n",
    "\n",
    "using namespace std;\n",
    "\n",
    "class Solution {\n",
    "public:\n",
    "    map<int, vector<int>> d;\n",
    "    Solution(vector<int>& nums) {\n",
    "        for (int i=0; i<nums.size(); i++) {\n",
    "            const auto v = nums[i];\n",
    "            if (d.find(v) == d.end()) {\n",
    "                //d.insert(vector<int> {i});\n",
    "                d[v].push_back(i);\n",
    "            } else {\n",
    "                d[v].push_back(i);\n",
    "            }\n",
    "        }\n",
    "    }\n",
    "    \n",
    "    int pick(int target) {\n",
    "        //6:45\n",
    "        return d[target][rand() % d[target].size()]; \n",
    "        //6:52\n",
    "    }\n",
    "};\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cleared-circus",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C++17",
   "language": "C++17",
   "name": "xcpp17"
  },
  "language_info": {
   "codemirror_mode": "text/x-c++src",
   "file_extension": ".cpp",
   "mimetype": "text/x-c++src",
   "name": "c++",
   "version": "17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
